Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn on premultiplied alpha (and alpha) by default #5917

Merged
merged 3 commits into from
Dec 23, 2022

Conversation

davepagurek
Copy link
Contributor

Resolves #5891 (also #5634, #5890, closed because the change was intentional, but it seems like the change is confusing for users.)

Changes

High level

Notes

  • As in WebGL blending doesn't always work with transparent textures #5854, WebGL MULTIPLY also multiplies the alpha channel instead of 2D mode, where it blends with white before multiplying.
  • LIGHTEST and DARKEST unfortunately work less well with premultiplied alpha, as 2D mode takes the max/min of the un-premultiplied channel values. This is a downgrade from before
  • SCREEN, REMOVE, and EXCLUSION handle semitransparency better now
  • Unlike my initial thoughts in Default WebGL premultipliedAlpha to true? #5891, I did not end up setting gl.pixelStorei(gl.UNPACK_PREMULTIPLIED_ALPHA, true), because the other color inputs to shaders are unmultiplied. (If we choose to keep our shaders the same and instead change our color inputs to them, we would need to turn this setting on to match.)

Live test files

Screenshots of the change

Antialiasing on clear backgrounds

function setup() {
  createCanvas(400, 400, WEBGL);
  pixelDensity(2);
  setAttributes({
    alpha: true,
    premultipliedAlpha: true
  });
  noFill();
  stroke(200, 200, 255);
  strokeWeight(1);
}
function draw() {
  // black w/ alpha zero
  background(0, 0, 0, 0);
  scale(4);
  box();
  noLoop();
}
premultipliedAlpha: falsepremultipliedAlpha: true

Blend modes on a clear background

In each screenshot, the left column is 2D mode, and the right column is WebGL mode.

Semitransparent white

Before After
image image

Semitransparent black

Before After
image image

PR Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default WebGL premultipliedAlpha to true?
2 participants